﻿using B.S.BaseData.Api.Write.Applicantion.Command;
using B.S.BaseData.ErrorCode;
using B.S.BaseData.Infrastructure.Interface;
using B.S.BataBase.Domain;
using MediatR;
using Microsoft.AspNetCore.Identity;

namespace B.S.BaseData.Api.Write.Applicantion.Handler
{
    public class UserDeleteCommandHandler : IRequestHandler<UserDeleteCommand, APIResult<int>>
    {
        private readonly IBaseRepository<UserModel> baseRepository;
        public UserDeleteCommandHandler(IBaseRepository<UserModel> baseRepository)
        {
            this.baseRepository = baseRepository;
        }
        public async Task<APIResult<int>> Handle(UserDeleteCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result=new APIResult<int>();
            var list =await baseRepository.GetValues(x=>x.Id==request.Id);
            list.IsDeleted= true;
            await baseRepository.UpdateAsync(list);
            result.Code = ApiEnum.Success;
            result.Msg = "用户信息删除成功";
            result.Data = 1;
            return await Task.FromResult(result);
        }
    }
}
